// @ts-nocheck
import {useEffect, useState} from 'react'
import {querySubDistrictByDistrict} from '@/services/subDistrict'
import {Select} from 'antd'

const SubDistrictSelect = (props) => {
  const {defaultValue, onChange, district, back} = props
  const [value, setValue] = useState(null)
  const [data, setData] = useState([])
  useEffect(() => {
    /*判断默认值*/
    if (back) {
      console.log(defaultValue)
      setValue(defaultValue)
    } else {
      setValue(null)
    }
    querySubDistrictByDistrict({district_id: district}).then(res => {
      setData(res.data)
    })

  }, [district])
  return (
    <Select
      value={value}
      allowClear
      showSearch
      onChange={(e)=>{setValue(e);onChange(e)}}
      placeholder={'请选择所属街道'}
    >
      {data.map(v => <Select.Option key={v.subdistrict_id} value={v.subdistrict_id}>{v.name}</Select.Option>)}
    </Select>
  );
};

export default SubDistrictSelect;
